package uns.fit.gis.contextmenu;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;

import uns.fit.gis.MapDrawer;
import uns.fit.gis.alg.RoutingAlgorithm;
import uns.fit.gis.i18n.LocaleManager;
import uns.fit.gis.mapdrawer.ActionCode;
import uns.fit.gis.mapdrawer.MapCanvas;

public class SearchLocationContextMenu extends ContextMenu {
	public SearchLocationContextMenu() {
		commands = new Command[4];
		commands[0]= new Command(LocaleManager.getMessage("menu"), Command.ITEM, 1);
		commands[1]= new Command(LocaleManager.getMessage("nextresultlocation"), Command.ITEM, 1);
		commands[2]= new Command(LocaleManager.getMessage("viewbestroute"), Command.ITEM, 1);
		commands[3] = new Command(LocaleManager.getMessage("exit"), Command.EXIT, 1);
	}
	public void commandAction(Command arg0, Displayable arg1) {
		if(arg0 == commands[0]) {
			MapDrawer.getMidlet().showMenuCanvas();
		}
		else if(arg0 == commands[1]) {
			if (MapDrawer.getMidlet().locationForm != null) {
				MapDrawer.getMidlet().locationForm.centerNextPlace();
            }
		}
		else if(arg0 == commands[2]) {
			if(MapCanvas.alg == null) {
				MapCanvas.alg = new RoutingAlgorithm();
			}
			MapCanvas.alg.setSource(MapDrawer.getMidlet().locationForm.getX(), MapDrawer.getMidlet().locationForm.getY());
			MapCanvas.alg.setDestination(MapCanvas.cursorCenterX, MapCanvas.cursorCenterY);
			MapCanvas.alg.runDijstraAlg();
			MapDrawer.getMidlet().showBestRouteList();
		}
		else if(arg0 == commands[3]) {
			MapDrawer.getMidlet().mapCanvas.commandAction(ActionCode.DESTROY_APP);
		}
	}
}
